require(["config"],function(){
    require(["jquery","header","cookie"],function($){
        function Login(){
            // console.log(1);
            this.addListener();
        }

        $.extend(Login.prototype,{
            constructor: Login,
            addListener:function(){
                console.log(this.loginHandler);
                $(".login-form").on("submit",$.proxy(this.loginHandler,this));
            },

            loginHandler: function(){
                // e.preventDefault();
                var data = $(".login-form").serialize();
                console.log(data);
                var url = "http://localhost/LIZI/api/login.php";
                $.post(url,data,this.loginSuccessHandler,"json");
                return false;
            },

            loginSuccessHandler: function(data){
                console.log(data);
                if(data.res_code === 1){
                    console.log(data);
                    $.cookie.json = true;
                    $.cookie("login-user",data.res_body.phone,{path:"/"});
                    location = "/";
                }else{
                    $(".error").removeClass("hidden");
                }
            }


        });

        new Login();
    });
});